package com.codesuc.aichat.aiAgent.factory;

import com.codesuc.aichat.aiAgent.strategy.AIService;
import jakarta.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: ZhangGongMing
 * @CreateTime: 2025/9/24 00:11
 * @description: AIService 策略工厂类
 * @Version: 1.0
 */
@Slf4j
@Component
public class AIServiceFactory {

    @Autowired
    private List<AIService> serviceList;

    // 策略映射表
    private final Map<String, AIService> serviceMap = new HashMap<>();

    @PostConstruct
    public void init() {
        for (AIService service : serviceList) {
            serviceMap.put(service.getServiceName(), service);
        }
        log.info(" AIService Init Success，服务提供商数量：{}", serviceMap.size());
    }

    /**
     * 根据服务提供商名称获取对应的 AIService 实例
     *
     * @param providerName 服务提供商名称
     * @return 对应的服务提供商的 AIService 实例
     */
    public AIService getAIService(String providerName) {
        return serviceMap.get(providerName);
    }

}
